package com.appdemo.demo;


import java.util.Arrays;

public enum ShareTypeEnum implements EnumCode<Integer> {

    // 价格比例
    PRICE_SCALE(0),

    // 件数
    PIECE(1);

    private Integer code;

    @Override
    public Integer getCode() {
        return code;
    }

    ShareTypeEnum(Integer code) {
        this.code = code;
    }

    public static <T> ShareTypeEnum of(T codeEnum) {
        if (codeEnum instanceof EnumCode) {
            return Arrays.stream(values()).filter(unitEnum -> unitEnum.code.equals(((EnumCode<?>) codeEnum).getCode())).findFirst()
                    .orElseThrow(() -> new RuntimeException("error"));
        }
        return PRICE_SCALE;

    }
}
